﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SNPAD
{
    public partial class Settings_Form : Form
    {
        public Settings_Form()
        {
            InitializeComponent();
        }

        private void System_Form_Load(object sender, EventArgs e)
        {
            try
            {
                this.MaximizeBox = false;//
                txtServer.Text = Configuration.Instance.GetString(ConfigurationKeys.OleDb_DbServer);
                txtDataBase.Text = Configuration.Instance.GetString(ConfigurationKeys.OleDb_DbName);
                txtUid.Text = Configuration.Instance.GetString(ConfigurationKeys.OleDb_DbUser);
                txtPwd.Text = Configuration.Instance.GetString(ConfigurationKeys.OleDb_DbPassord);
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void btn_hold_Click(object sender, EventArgs e)
        {
            Configuration.Instance.SetValue(ConfigurationKeys.OleDb_DbServer, txtServer.Text);
            Configuration.Instance.SetValue(ConfigurationKeys.OleDb_DbName, txtDataBase.Text);
            Configuration.Instance.SetValue(ConfigurationKeys.OleDb_DbUser, txtUid.Text);
            Configuration.Instance.SetValue(ConfigurationKeys.OleDb_DbPassord, txtPwd.Text);

            string connstr = "Data Source=" + Configuration.Instance.GetString(ConfigurationKeys.OleDb_DbServer);
            connstr += "," + Configuration.Instance.GetString(ConfigurationKeys.OleDb_DbPort) + ";";
            connstr += "Persist Security Info=False;User ID=" + Configuration.Instance.GetString(ConfigurationKeys.OleDb_DbUser) + ";";
            connstr += "Password=" + Configuration.Instance.GetString(ConfigurationKeys.OleDb_DbPassord) + ";";
            connstr += "Initial Catalog=" + Configuration.Instance.GetString(ConfigurationKeys.OleDb_DbName) + ";";

            Configuration.Instance.SetValue(ConfigurationKeys.ConnectionString, connstr);
            Configuration.Instance.Save();

            MessageBox.Show("保存成功！\nSave success!  ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
